package sfeir.authform.server.taglib;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import sfeir.authform.server.authservice.AuthService;
import sfeir.authform.server.authservice.AuthServiceFactory;

public class LogoutLink extends TagSupport {
    private String logoutLabel = "Email";
    private String returnURL = "/";
    
    /**
     * 
     */
    private static final long serialVersionUID = -3937034608298993606L;

    @Override
    public int doStartTag() throws JspException {
        AuthService service = AuthServiceFactory.getAuthService(pageContext.getSession());
        Writer out = pageContext.getOut();
        try {
            out.write("<a href=\"");
            out.write(service.createLogoutURL(returnURL));
            out.write("\">");
            out.write(logoutLabel);
            out.write("</a>");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return SKIP_BODY;
    }

    public String getReturnURL() {
        return returnURL;
    }

    public void setReturnURL(String returnURL) {
        this.returnURL = returnURL;
    }

    public String getLogoutLabel() {
        return logoutLabel;
    }

    public void setLogoutLabel(String logoutLabel) {
        this.logoutLabel = logoutLabel;
    }
}
